package com.streamer.app.utils.http

import com.streamer.app.utils.ActivityUtils
import com.streamer.app.utils.ToastUtil
import com.streamer.app.utils.UserManager.logout
import com.youpai.yingteda_android.util.NetCode


/**
 * author:cb
 * createTime: 2022/6/7 10:54
 **/
object NetError {
    fun handleNetError(msg: String, code: Int, isShowToast: Boolean = true) {
        if (code == NetCode.ERROR_CODE_OK) return
        when (code) {
            NetCode.ERROR_CODE_CONNECTION ->{
                ToastUtil.toastShortMessage("网络异常")

            }
            NetCode.ERROR_CODE_RECHARGE -> {
//                ActivityUtils.getTopActivity()?.showRechargeDialog(msg)

            }
            NetCode.ERROR_CODE -> {
                ToastUtil.toastShortMessage("数据异常")

            }
            NetCode.ERROR_CODE_LOGIN_ERROR -> {
                //登录状态已过期 - 不自动登出，只显示提示
                ToastUtil.toastShortMessage("登录状态已过期，请重新登录")
                // 注释掉自动登出，让用户手动处理
                 logout()

            }
            else -> {
                if (isShowToast)
                    ToastUtil.toastShortMessage(msg)
            }
        }


    }
}